package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;

/**
 * @author youli.chen
 * @Description: 公海池规则枚举类
 * @date 2019/1/24 15:24
 */
@Getter
public enum CustomerRuleEnum {
    /**
     * 无新建跟进客户规则
     */
    NO_CUSTOMER_COMMUNICATE_RULE(1, "enum.customerRule.name.no_customer_communicate_rule", "rule1", "enum.customerRule.tip.no_customer_communicate_rule"),
    /**
     * 无新建机会客户规则
     */
    NO_OPPORTUNITY_RULE(2, "enum.customerRule.name.no_opportunity_rule", "rule2", "enum.customerRule.tip.no_opportunity_rule"),
    /**
     * 无签订合同客户规则
     */
    NO_CONTRACT_RULE(3, "enum.customerRule.name.no_contract_rule", "rule3", "enum.customerRule.tip.no_contract_rule"),
    /**
     * 最大拥有客户数规则
     */
    MAX_CUSTOMER_NUM_RULE(4, "enum.customerRule.name.max_customer_num_rule", "rule4", "enum.customerRule.tip.max_customer_num_rule"),
    /**
     * 前负责人规则
     */
    PRE_PRINCIPAL_RULE(5, "enum.customerRule.name.pre_principal_rule", "rule5", "enum.customerRule.tip.pre_principal_rule"),
    /**
     * 捞取频率限制规则
     */
    GAIN_RATE_RULE(6, "enum.customerRule.name.gain_rate_rule", "rule6", "enum.customerRule.tip.gain_rate_rule"),
    /**
     * 未知规则,当异常时用于返回
     */
    UNKNOWN(404, "enum.customerRule.name.unknown", "unknown", "");


    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;

    /**
     * 枚举描述 --英文名称
     */
    private final String alias;

    /**
     * 枚举描述 --提示
     */
    private final String tip;

    /**
     * 构造一个<code>SubModuleEnum</code>枚举对象
     *
     * @param code  枚举值
     * @param name  枚举名
     * @param alias 别名
     */
    CustomerRuleEnum(int code, String name, String alias, String tip) {
        this.code = code;
        this.name = name;
        this.alias = alias;
        this.tip = tip;
    }

    /**
     * 通过枚举<code>alias</code>获得枚举
     *
     * @param alias 别名
     * @return PublicCustomerRuleEnum
     */
    public static CustomerRuleEnum getByAlias(String alias) {
        for (CustomerRuleEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code 枚举值
     * @return PublicCustomerRuleEnum
     */
    public static CustomerRuleEnum getByCode(Integer code) {
        for (CustomerRuleEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<PublicCustomerRuleEnum>
     */
    public static List<CustomerRuleEnum> getAllEnum() {
        List<CustomerRuleEnum> list = new ArrayList<>();
        for (CustomerRuleEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (CustomerRuleEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getTip() {
        return I18nMessageUtil.getMessage(tip);
    }

}
